<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<jsp:include page="admin/common/Userheader.jsp"></jsp:include>
<script src="${pageContext.request.contextPath}/views/js/libs/jquery-1.12.4.js" type="text/javascript"></script>
<link href="${pageContext.request.contextPath}/views/js/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/views/js/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />

<script src="${pageContext.request.contextPath}/views/js/ligerUI/js/core/base.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/views/js/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/views/js/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/views/js/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/views/js/utils.js" type="text/javascript"></script> 
<!DOCTYPE html>
<html lang="zh-CN" style="overflow-x:hidden; display: block; width: 960px;">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>Bootstrap Template</title>
    
    <!-- Bootstrap -->
    <link href="${pageContext.request.contextPath}/views/css/bootstrap.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="${pageContext.request.contextPath}/views/js/html5shiv.min.js"></script>
      <script src="${pageContext.request.contextPath}/views/js/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/views/css/home.css">
    <style>

    </style>
</head>

<body>
    <input type="hidden" id="orderid1" value="asc"/>
    <input type="hidden" id="orderid2" value="asc"/>
    <input type="hidden" id="orderid3" value="asc"/>
    <input type="hidden" id="orderid4" value="asc"/>
    <input type="hidden" id="orderid5" value="asc"/>
    <input type="hidden" id="orderid6" value="asc"/>
    <input type="hidden" id="seldepartid" value="${selDepartId}"/>
    <input type="hidden" id="pageIndex" />
<!--     上级文件夹id -->
    <input type="hidden" id="upid" value="${upid }" />
    
    <div class="tab_content" style="${two}">
    	<a href="javascript:;" style="${folder}" onclick="foldermanage();">文件管理</a>
    	<a href="javascript:;" class="current" style="${users}" onclick="usersmanage();">用户管理</a>
    </div>
    
    <!--右侧内容区-->
            <div class="pull-left right-components" style="width: 100%; margin-left: 0">
                <!--右侧顶部-->
                <div class="right-header-component clearfix tool">
                    <div class="pull-left" style="margin-left: 20px;">
                   		<button type="button" ${notallow } id="createfolderbut" class="btn btn-default dropdown-toggle" aria-haspopup="true" onclick="f_openfolder();">
                           	新建文件夹
                        </button>
                        <button type="button" ${notallow } id="upfilebut" class="btn btn-default dropdown-toggle btn_nobg" onclick="f_upload();">
                             	上传文件
                        </button>
                        
                        <button type="button" ${notallow } id="delbut" class="btn btn-danger btn_nobg" aria-haspopup="true" onclick="batchDeleteFiles();">
                             	删除文件
                        </button>
                    </div>
                    <div class="pull-right">
                        <div class="pull-left right-search-component">
                            <input type="text" id="search_con" onkeyup="onSearch();" placeholder="搜索您的文件"/>
                            <i id="right_search_btn" onclick="BindData();"></i>
                        </div>
                        <div class="pull-right header-text-component">
                            <p class="pull-left">
                                文件数：<span id="totalfileNum">0</span>
                            </p>
                            <p class="pull-left">
                                总大小：<span id="totalfilesize">0</span><span>M</span>
                            </p>
                        </div>
                    </div>
                </div>

                <!--右侧内容区-->
                <div class="form-component">

                    <div class="panel panel-default">
                        <!-- 路径导航 -->
                        <ol class="breadcrumb" id="breadcrumb">
                        </ol>

                        <!-- Table -->
                        <table border="0" cellspacing="0" cellpadding="0" >
                            <thead>
	                            <tr>
	                                <th><input type="checkbox" id="checkall"></th>
	                                <th align="left" onclick="BindOrderData(1);" style="padding-left: 28px;text-align:left;cursor:pointer"><a >文件名</a><span id="1paixud"></span></th>
	                                <th onclick="BindOrderData(2);" style="cursor:pointer">大小<span id="2paixud"></span></th>
	                                <th></th>
	                                <th onclick="BindOrderData(5);" style="cursor:pointer">属性<span id="5paixud"></span></th>
	                                <th onclick="BindOrderData(3);" style="cursor:pointer">修改日期<span id="3paixud"></span></th>
	                                <th onclick="BindOrderData(6);" style="cursor:pointer">创建者<span id="6paixud"></span></th>
	                                <th onclick="BindOrderData(4);" style="cursor:pointer">修改者<span id="4paixud"></span></th>
	                            </tr>
	                            <tbody id="tb_body">
								</tbody>
                            </thead>
                            
                        </table>
						
                        
                    </div>
                </div>
            </div>
    	<form id="downloadFile" action="${pageContext.request.contextPath}/file/downloadfile" style="display: none;" method="post">
			<input id="downloadfileId" type="hidden" name="fileId">
		</form>
		<!-- 模态确认框 -->
<!-- 		<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title" id="myModalLabel">操作提示</h4>
		            </div>
		            <div class="modal-body">确认删除文件？</div>
		            <div id="deletesuccess" class="alert alert-success hide"></div>
		            <div class="modal-footer">
		                <button type="button" class="btn btn-primary" onclick="ajaxDelete();">确定</button>
		                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		            </div>
		        </div>
		    </div>
		</div>  -->
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="${pageContext.request.contextPath}/views/js/bootstrap.min.js"></script>
    <script>
    	ifOrderbyName = "0";
        $(function(){
			$('#checkall').change(function(){
				//判断如果是不可选的话就不用管
				//$(this).parents('table:first').find('input').prop('checked', $(this).is(':checked')); 
				var list = $(this).parents('table:first').find('input'); 
				for(var i=0;i<list.length;i++){
					//alert(list.eq(i).attr('disabled'));
					//如果定义的话，说明是不可选的
					if(!list.eq(i).attr('disabled')){
						list.eq(i).prop('checked', $(this).is(':checked'));
					}
				}
		    });
			selDepartId = '${selDepartId}';
			selDepartName = '${selDepartName}';
			ownDepartId = '${sessionScope.departmentId}';
			//alert(selDepartId+selDepartName);
			BindData();
        })
        
        //。。。图标点击
		/* function checkMore(that){
			$(that).parent().find('p').show();
		} */
         
        function onSearch(){
        	if(event.keyCode==13){
        		ifOrderbyName = "";
        		for (var i = 1; i < 6; i++) {
        			$('#'+i+'paixud').html('');
				} 
				BindData();
        		
        	}
        }
        
        function BindOrderData(ordertype){
        	ifOrderbyName = ordertype;
        	BindData();
        }
        //右侧加载数据 
		function BindData(){
        	var search_str = $('#search_con').val();
        	var orderValue = "";
        	//debugger;
        	//alert(orderValue);
        	//如果是点文件名的话走这段
        	var orderColumn = "";
        	for (var j = 1; j < 7; j++) {
        		//按文件名排序
	        	if(ifOrderbyName==j){
	        		orderValue = $('#orderid'+j).val();
	        		//alert(orderValue);
	        		if(orderValue=='asc'){
	    				$('#orderid'+j).val('desc');
	    				$('#'+j+'paixud').html('<img id="'+j+'paixu" alt="" src="${pageContext.request.contextPath}/views/img/orderup.png">');
	    				//$('#'+j+'paixu').attr("src","${pageContext.request.contextPath}/views/img/orderup.png");
	    				//alert(orderValue);
	    			}else{
	    				$('#orderid'+j).val('asc');
	    				$('#'+j+'paixud').html('<img id="'+j+'paixu" alt="" src="${pageContext.request.contextPath}/views/img/orderdown.png">');
	    				//$('#'+j+'paixu').attr("src","${pageContext.request.contextPath}/views/img/orderdown.png");
	    				//alert(orderValue);
	    			}
	        		if(j==1){
		        		orderColumn = "convert(file_name using gbk)";
	        		}
	        		if(j==2){
		        		orderColumn = "file_size";
	        		}
	        		if(j==3){
		        		orderColumn = "rtime";
	        		}
	        		if(j==4){
		        		orderColumn = "ruser";
	        		}
	        		if(j==5){
		        		orderColumn = "file_character";
	        		}
	        		if(j==6){
		        		orderColumn = "user_id";
	        		}
	        		for (var i = 1; i < 7; i++) {
	        			if(i!=j){
	        				$('#'+i+'paixud').html('');
		        			//$('#'+i+'paixu').attr("src","");
	        			}
					} 
	        	}
			}
        	
        	
        	
			//alert(orderValue);
			
			$.ajax({
				type : "post",
				url : "${pageContext.request.contextPath}/file/ajaxselectonepage",
				data : {
					'selDepartmentId':selDepartId,
					'selfilePath':selDepartName,
					"searchCon":search_str,
					"orderColumn":orderColumn,
					"orderValue":orderValue
				},
				dataType : "json",
				success : function(data) {
					if(data){
						$('#breadcrumb').empty();
						$('#breadcrumb').append(data.html_str);
						//是否是同一个部门
						var ifonedepartval = data.ifonedepart;
						//不是同一个部门，不能创建删除等
						if(ifonedepartval){
							$('#createfolderbut').attr("disabled",true);
							$('#upfilebut').attr("disabled",true);
							$('#delbut').attr("disabled",true);
						}
						//总文件数和总大小
						$('#totalfileNum').html(data.totalfileNum);
						var totalfilesize = fmoney(data.totalfilesize/1024,2);
						$('#totalfilesize').html(totalfilesize);
						
						var curPageIndex = data.curPage;//当前页码
						var total = data.total;//数据总条数
						var totalPage = data.totalPage;//页面总数
						if(data.data){
							var msg = data.data;
							$('#tb_body').empty();
							$.each(data.data,function(i, item) {
								var dateVal = "";
								if (item.rtime != null
										&& item.rtime != "") {
									var dateV = new Date();
									dateV.setTime(item.rtime);
									dateVal = dateV
											.Format('yyyy-MM-dd hh:mm:ss');
	
								}
								var status = "";
								var iffolder = "";
								if(item.fileType==0){
									iffolder = "夹";
								}
								if(item.fileCharacter==1){
									status = "部门文件"+iffolder;
								}else if(item.fileCharacter==0){
									status = "共享文件"+iffolder;
								}else if(item.fileCharacter==2){
									status = "个人文件"+iffolder;
								}
								//文件记录操作权限判断开始
								var fileUserId = item.userId;//文件记录上传用户Id
								var fileDepartmentId = item.departmentId;//文件记录所属部门Id
								var fileProperty = item.fileCharacter;//文件属性
								var moveOperate = false;//移动操作权限
								var copyOperate = false;//复制操作权限
								var renameOperate = false;//重命名操作权限
								var setPropertyOperate = false;//设置属性权限,该功能暂时删除，所以权限都是false后面不用判断
								var deleteOperate = false;//删除权限
								var downloadOperate = false;//下载权限，该权限判断不包含(是文件和文件夹类型的判断)
								var previewOperate = false;//预览权限
								var userRole = ${sessionScope.userRole};//当前用户角色
								var userDepartmentId = ${sessionScope.departmentId};//当前用户所属部门Id
								var userId = ${sessionScope.uid};//当前用户Id
								if(userRole != null && 0==userRole){
									//如果是个人角色
									if(userId==fileUserId){
										//如果文件用户Id==当前用户Id，那么该用户可以对这条记录进行移动、复制、删除、重命名、下载
										moveOperate = true;
										copyOperate = true;
										renameOperate = true;
										deleteOperate = true;
										downloadOperate = true;
										previewOperate = true;
									}else{
										//当文件记录用户Id != 当前用户Id时
										if(userDepartmentId==fileDepartmentId){
											//如果当前用户部门==文件记录所属部门 或者 文件记录共享属性那么该用户可以进行查看、下载、复制
											copyOperate = true;
											downloadOperate = true;	
											previewOperate = true;
										}else if(userDepartmentId != fileDepartmentId && fileProperty==0){
											//如果是非当前用户部门，的共享文件，那么该用户可以进行下载、查看、复制
											copyOperate = true;
											downloadOperate = true;	
											previewOperate = true;
										}
									}
								}else if(userRole != null && 1==userRole){
									//如果是部门管理员
									if(userId==fileUserId){
										//如果是部门管理员自己创建的文件记录，那么赋予所有权限
										moveOperate = true;
										copyOperate = true;
										renameOperate = true;
										deleteOperate = true;
										downloadOperate = true;
										previewOperate = true;
									}else{
										//如果不是部门管理自己创建的记录，但是 如果当前用户部门 == 文件记录所属部门 
										if(userDepartmentId==fileDepartmentId){
											moveOperate = true;
											copyOperate = true;
											renameOperate = true;
											deleteOperate = true;
											downloadOperate = true;
											previewOperate = true;
										}else if(userDepartmentId != fileDepartmentId && fileProperty==0){
											//如果当前用户部门 != 文件记录所属部门
											copyOperate = true;
											downloadOperate = true;
											previewOperate = true;
										}										
									}
								}else if(userRole != null && 3==userRole){
									//如果是超级管理员
									moveOperate = true;
									copyOperate = true;
									renameOperate = true;
									deleteOperate = true;
									downloadOperate = true;
									previewOperate = true;
								}
								//文件记录操作权限判断结束
								var iffolder_begin = "";
								var iffolder_end = "";
								var href_str = "href='###' onclick='preview("+item.id+","+item.fileSize+")'";
								var if_folder = "";
								var if_file_pre = "";
								//开始生成文件记录操作功能按钮
								/* var if_own_depart = "";
						    	if_own_depart = "<div onclick='checkMore(this);' class='tool_more'><img src='${pageContext.request.contextPath}/views/img/more.png'>"+
							    "<p id='checkmore'>"+
						    	"<span class='icon_arrow'></span>";
						    	if(moveOperate){
						    		if_own_depart += "<a href='javascript:;' onclick='moveto("+item.id+","+item.fileType+")'>移动到</a>";
						    	}
						    	if(copyOperate){
						    		if_own_depart += "<a href='javascript:;' onclick='copyto("+item.id+","+item.fileType+")'>复制到</a>";
						    	}
						    	if(renameOperate){
						    		if_own_depart += "<a href='javascript:;' onclick='renameFilePage("+item.id+");'>重命名</a>";
						    		
						    	}
						    	if(setPropertyOperate){
						    		if_own_depart += "<a href='javascript:;' onclick='character("+item.id+","+item.fileCharacter+");'>属性</a>";
						    	}
						    	if(deleteOperate){
						    		if_own_depart += "<a href='javascript:;' onclick='delone("+item.id+","+item.fileType+");'>删除</a>";
						    	}
						    	if_own_depart += "</p>"+"</div>"; */						    	
						    	var if_own_depart = "";
						    	if_own_depart = "<div onclick='checkMore(this);' class='tool_more'>";
						    	if(moveOperate){
						    		if_own_depart += "<img src='${pageContext.request.contextPath}/views/img/td_icon03.png' title='移动到' onclick='moveto("+item.id+","+item.fileType+")'>";
						    	}
						    	if(copyOperate){
						    		if_own_depart += "<img src='${pageContext.request.contextPath}/views/img/td_icon04.png' title='复制到' onclick='copyto("+item.id+","+item.fileType+")'>";
						    	}
						    	if(renameOperate){
						    		if_own_depart += "<img src='${pageContext.request.contextPath}/views/img/td_icon05.png' title='重命名' onclick='renameFilePage("+item.id+");'>";
						    		
						    	}
						    	if(setPropertyOperate){
						    		if_own_depart += "<img src='${pageContext.request.contextPath}/views/img/td_icon06.png' title='属性' onclick='character("+item.id+","+item.fileCharacter+");'>";
						    	}
						    	if(deleteOperate){
						    		if_own_depart += "<img style='magin-right:0;' src='${pageContext.request.contextPath}/views/img/td_icon07.png' title='删除' onclick='delone("+item.id+","+item.fileType+");'>";
						    	}
						    	if_own_depart += "</div>";
						    	//生成文件记录操作功能按钮结束
								/**
							    if(selDepartId==ownDepartId){
							    	if_own_depart = "<div onclick='checkMore(this);' class='tool_more'><img src='${pageContext.request.contextPath}/views/img/more.png'>"+
								    "<p id='checkmore'>"+
							    	"<span class='icon_arrow'></span>"
							    	"<a href='javascript:;' onclick='moveto("+item.id+","+item.fileType+")'>移动到</a>"+
							    	"<a href='javascript:;' onclick='copyto("+item.id+","+item.fileType+")'>复制到</a>"+
							    	"<a href='javascript:;' onclick='renameFilePage("+item.id+");'>重命名</a>"+
							    	"<a href='javascript:;' onclick='character("+item.id+","+item.fileCharacter+");'>属性</a>"+
							    	"<a href='javascript:;' onclick='delone("+item.id+");'>删除</a>"+
							    	"</p>"+
								    "</div>";
							    }else{
							    	//不是同一个部门的话
							    	if(item.fileType=='0'){
							    		if_own_depart = "";
							    	}else{
							    		if_own_depart = "<div onclick='checkMore(this);' class='tool_more'><img src='${pageContext.request.contextPath}/views/img/more.png'>"+
									    "<p id='checkmore'><span class='icon_arrow'></span><a href='javascript:;' onclick='copyto("+item.id+","+item.fileType+")'>复制到</a></p>"+
									    "</div>";
							    	}
							    }
								*/
								var selDepartName = item.filePath+"/"+item.fileName;
								selDepartName = encodeURI(encodeURI(selDepartName));
								//判断是否文件夹,0是文件夹
								if(item.fileType=='0'){
									var iffolder_begin = "<span class='folder'>";
									var iffolder_end = "</span>";
//									href_str = "href='index_right?selDepartId="+selDepartId+"&selDepartName="+selDepartName+"'";
									href_str = "href='index_rightonepage?selDepartId="+selDepartId+"&selDepartName="+selDepartName+"&fileCharacter="+item.fileCharacter+"&upid="+item.id+"'";
								}else{
									//if_file_pre = "<img src='${pageContext.request.contextPath}/views/img/share.png'>";
									if_folder = "<img src='${pageContext.request.contextPath}/views/img/download.png' title='下载'>";
								}
								var fileSize = item.fileSize;
								if(item.fileType=='0'){
									fileSize = "-";
								}else{
									if(fileSize!=0){
										var endsize = fmoney(fileSize/1024,2);
										if(endsize=='0.00'){
											endsize = '0.01';
										}
										fileSize = endsize + "M";
									}
								}
								//这个是分享图标  不要删掉
								//var share = "<a href='javascript:;'><img src='${pageContext.request.contextPath}/views/img/share.png'></a>"
								//文件记录选择按钮权限控制开始
								var disabled = "disabled=disabled";
								if(deleteOperate){
									disabled = "";
								}
								var cuser = "";
								if(item.cuser){
									cuser = item.cuser.username;
								}
								//文件记录选择按钮权限控制结束
								var htmlCon = "<tr valign='middle'>"+
													"<td width='63'><input name='checkFileId' type='checkbox' value='"+item.id+"' "+disabled+" ></td>"+
													"<td width='182' style='text-align:left;' class='word_length'>"+iffolder_begin+"<a "+href_str+" title='"+item.fileName+item.fileSuffix+"'>"+item.fileName+item.fileSuffix+"</a>"+iffolder_end+"</td>"+
													"<td width='100'>"+fileSize+"</td>"+
													"<td width='170' class='icon'>"+
													    "<div class='table_tools'>"+
													    "<div onclick='checkfileexists("+item.id+","+item.fileType+")'>"+if_folder+"</div>"+
													    if_own_depart+
													    "</div></td>"+
													"<td width='100'>"+status+"</td>"+
													"<td width='165'>"+dateVal+"</td>"+
													"<td width='80'>"+cuser+"</td>"+
													"<td  align='center'>"+item.users.username+"</td>"+
												"</tr>";
								$("#tb_body").append(htmlCon);
								
								//鼠标移入显示图标
								$('table tr').hover(function(){
									$(this).find('td.icon .table_tools').show();
								},function(){
									$(this).find('td.icon .table_tools').hide();
								});
								
							});
						}
					}
					
					
				},
				error : function() {
					//alert("网络错误！");
				}
			});
			
		}
        
        
        //弹窗
        //新建文件夹的页面
		function f_openfolder()
	       {
        	var upid = $('#upid').val();
	           $.ligerDialog.open({
	               height:260,
	               width: 320,
	               title : '新建文件夹',
	               url: '${pageContext.request.contextPath}/file/tocreatefolderpage?selFolder='+encodeURI(encodeURI(selDepartName))+"&selDepartId="+selDepartId+"&upid="+upid+"&fileCharacter="+"${fileCharacter}", 
	               showMax: false,
	               showToggle: true,
	               showMin: false,
	               isResize: true,
	               slide: false,
	               data: {
	                   selFolder:selDepartName,
	                   selDepartId:selDepartId
	               },
	               //自定义参数
	               myDataName: $("#txtValue").val()
	           });
	       } 
        
		//到上传文件的页面
		function f_upload(){
			var upid = $('#upid').val();
    	   $.ligerDialog.open({
               height: 270,
               width: 320,
               title : '上传文件',
               url: '${pageContext.request.contextPath}/file/touploadpage?selFolder='+encodeURI(encodeURI(selDepartName))+"&selDepartId="+selDepartId+"&upid="+upid+"&fileCharacter="+"${fileCharacter}", 
               showMax: false,
               showToggle: true,
               showMin: false,
               isResize: true,
               slide: false,
               closeable:false,
               data: {
                   selFolder:$('#selFolder').val(),
                   selDepartId:selDepartId
               },
               //自定义参数
               myDataName: $("#txtValue").val()
           });
       }
        
		//检查文件是否存在
		function checkfileexists(fileId,fileType){
			if(fileType == 0){
				//alert('您不能下载整个目录');
				operationTips('您不能下载整个目录!');
				return ;				
			}
			/**
			$.ajax({
				type:'post',
				url:'${pageContext.request.contextPath}/file/checkfileexists',
				dataType:'json',
				data:{
					"fileId":fileId
				},
				success:function (rtn) {
					if(rtn.code == 0 ){
						downloadFile(fileId);
					}else{
						//alert(rtn.msg);
						operationTips(rtn.msg+"！");
					}
				},
				error:function (XMLHttpRequest, textStatus, errorThrown) {
					if(XMLHttpRequest.status=='405'){
						//登录超时跳转
						parent.window.location.href='${pageContext.request.contextPath}/login/login';
					}
					operationTips('请求出错!');
				}
			});
			*/
			downloadFile(fileId);
		}
		//下载文件
		function downloadFile(fileId) {
			$("#downloadfileId").val(fileId);
			$("#downloadFile").submit();
		}
		//删除文件
		 function batchDeleteFiles() {
			var fileIds = '';
			$("input[name='checkFileId']:checked").each(function() {
				fileIds += $(this).val() + ',';
			});
			if (fileIds == "") {
				//alert("请选择要删除的数据!");
				operationTips('请选择要删除的数据！');
				return;
			}
			$.ligerDialog.confirm('确认删除文件？', function (yes) {
				if(yes==true){
					ajaxDelete(); 
				}	
				});
			//confirmDeleteFile();
		}
		//删除文件确认
		function confirmDeleteFile(){
			//还原提示框
			$("#deletesuccess").attr("class","alert alert-success hide");
			$("#deletesuccess").html("");
			$('#confirmModal').modal({'show':true,'backdrop': 'static', 'keyboard': false});
		}
		function delone(id,filetype){
			$("#tb_body").find('td.icon .table_tools').hide();
			/* $("#tb_body").find('p#checkmore').hide(); */
			var msg = "";
			if(filetype=='0'){
				msg = "删除文件夹，将删除文件夹下所有的子文件夹和文件，确定要删除吗？";
			}else{
				msg = "确认删除文件？";
			}
			$.ligerDialog.confirm(msg, function (yes) {
				if(yes==true){
					ajaxdelone(id); 
				}	
			});
		}
		function ajaxdelone(id){
			$.ajax({
				type : 'post',
				url : '${pageContext.request.contextPath}/file/deletefiles',
				dataType : 'json',
				data : {
					'fileIds' : id
				},
				success : function(rtn) {
					if (rtn.code == 0) {
						BindData(1);
						/* $("#deletesuccess").attr("class","alert alert-success");
						$("#deletesuccess").html("删除成功！2s后自动关闭...");
						setTimeout(function(){$("#confirmModal").modal("hide")},2000); */
						$.ligerDialog.waitting('删除成功！');
						setTimeout(function () { $.ligerDialog.closeWaitting(); }, 1000);
					} else {
						/* $("#deletesuccess").attr("class","alert alert-warning");
						$("#deletesuccess").html("失败！"+rtn.msg); */
						operationTips('删除失败!'+rtn.msg);
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					if(XMLHttpRequest.status=='405'){
						//登录超时跳转
						parent.window.location.href='${pageContext.request.contextPath}/login/login';
					}
					operationTips('请求异常！');
				}
			});
		}
		
		
		
		function ajaxDelete(){
			var fileIds = '';
			$("input[name='checkFileId']:checked").each(function() {
				fileIds += $(this).val() + ',';
			});
			$.ajax({
				type : 'post',
				url : '${pageContext.request.contextPath}/file/deletefiles',
				dataType : 'json',
				data : {
					'fileIds' : fileIds
				},
				success : function(rtn) {
					if (rtn.code == 0) {
						BindData(1);
						/* $("#deletesuccess").attr("class","alert alert-success");
						$("#deletesuccess").html("删除成功！2s后自动关闭...");
						setTimeout(function(){$("#confirmModal").modal("hide")},2000); */
						operationTips('删除成功！');
						$.ligerDialog.waitting('删除成功！');
						setTimeout(function () { $.ligerDialog.closeWaitting(); }, 1000);
					} else {
						/* $("#deletesuccess").attr("class","alert alert-warning");
						$("#deletesuccess").html("失败！"+rtn.msg); */
						operationTips('删除失败！'+rtn.msg);
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					if(XMLHttpRequest.status=='405'){
						//登录超时跳转
						parent.window.location.href='${pageContext.request.contextPath}/login/login';
					}
					operationTips('请求异常！');
				}
			});
		} 
		
		//预览
		function preview(itemid,filesize){
			if(filesize/1024>10){
				operationTips("不支持10M以上文件的预览");
				return;
			}
			
			$.ajax({
				type : "post",
				url : "${pageContext.request.contextPath}/file/previewfile",
				data : {
					fileId:itemid
				},
				dataType : "json",
				success : function(data) {
					if(data.code=='-1'){
						alert(data.msg);
					}
					var url = data.data.url;
					if(data.code=='0'){
						//window.open(data.data);
						var type = data.data.type;
						//如果是图片就在当前页面显示
						if(type==1){
							//alert(url);
							reSizePic(url);
						}
						else if(type==3){
							//alert(url);
							window.open(url);
						}
						else{
							window.open("${pageContext.request.contextPath}/file/preview?url="+url);
						}
					}
					/* else if(data.code=='1016'){
						alert(data.msg)
					} */
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					if(XMLHttpRequest.status=='405'){
						//登录超时跳转
						parent.window.location.href='${pageContext.request.contextPath}/login/login';
					}
					//alert("网络错误！");
				}
			});
			
			
		}
		
		function reSizePic( src ){
			
			parent.reSizePic(src);
		}
		
		//操作提示
		function operationTips(content){
			$.ligerDialog.alert(content);
		}
		
		//到"移动到"的界面
		function moveto(selid,filetype){
			$("#tb_body").find('td.icon .table_tools').hide();
			/* $("#tb_body").find('p#checkmore').hide(); */
			$.ligerDialog.open({
               height:690,
               width: 370,
               title : '移动到',
               url: encodeURI('${pageContext.request.contextPath}/file/tomovecopytopage?selid='+selid+"&selpath="+selDepartName+"&filetype="+filetype), 
               showMax: false,
               showToggle: true,
               showMin: false,
               isResize: true,
               slide: false,
               closeable:false,
               data: {
               }
           });
		}
		
		//到"复制到"的界面
		function copyto(selid,filetype){
			$("#tb_body").find('td.icon .table_tools').hide();
			/* $("#tb_body").find('p#checkmore').hide(); */
			$.ligerDialog.open({
               height:690,
               width: 370,
               title : '复制到',
               url: encodeURI('${pageContext.request.contextPath}/file/copyfileselectfolder?selid='+selid+"&selpath="+selDepartName+"&filetype="+filetype), 
               showMax: false,
               showToggle: true,
               showMin: false,
               isResize: true,
               slide: false,
               closeable:false,
               data: {
               }
           });
		}
		
		//到文件重命名页面
		function renameFilePage(selid){
			$("#tb_body").find('td.icon .table_tools').hide();
			/* $("#tb_body").find('p#checkmore').hide(); */
			$.ligerDialog.open({
               height:230,
               width: 330,
               title : '重命名',
               url: '${pageContext.request.contextPath}/file/torenamefilepage?selid='+selid, 
               showMax: false,
               showToggle: true,
               showMin: false,
               isResize: true,
               slide: false,
               closeable:false,
               data: {
               }
           });
		}
		
		function character(selid,fileCharacter){
			$("#tb_body").find('td.icon .table_tools').hide();
			/* $("#tb_body").find('p#checkmore').hide(); */
			$.ligerDialog.open({
               height:240,
               width: 300,
               title : '设置公开权限',
               url: '${pageContext.request.contextPath}/file/tochangecharacterpage?selid='+selid+'&fileCharacter='+fileCharacter, 
               showMax: false,
               showToggle: true,
               showMin: false,
               isResize: true,
               slide: false,
               closeable:false,
               data: {
               }
           });
		}
		
		//文件管理
		function foldermanage(){
			window.location.href = encodeURI('index_rightonepage?selDepartId=${selDepartId}'
					+ "&selDepartName=${selDepartName}");
		}
		//部门人员管理
		function usersmanage(){
			window.location.href = encodeURI('${pageContext.request.contextPath}/user/usermanage?selDepartId=${selDepartId}&selDepartName=${selDepartName}');
		}
    </script>
</body>

</html>